//
//  ViewController.m
//  20-Homework
//
//  Created by dllo on 16/8/10.
//  Copyright © 2016年 ZHW. All rights reserved.
//

#import "ViewController.h"
#import "GDataXMLNode.h"
#import "AlbumInfo.h"
@interface ViewController ()
@property (nonatomic, strong) NSMutableArray<AlbumInfo *> *albumInfoArray;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.albumInfoArray = [NSMutableArray array];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Cartoon" ofType:@"xml"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSError *error = nil;
    
    GDataXMLDocument *document = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error];
    GDataXMLElement *rootElement = document.rootElement;
    for (GDataXMLElement *childElement in rootElement.children) {
        for (GDataXMLElement *element in childElement.children) {
            if ([element.name isEqualToString:@"AlbumInfo"]) {
                AlbumInfo *albumInfo = [[AlbumInfo alloc] init];
                [_albumInfoArray addObject:albumInfo];
    
                for (GDataXMLElement *subElement in element.children) {
//                    NSLog(@"subElement = %@", subElement.name);
                    [albumInfo setValue:subElement.stringValue forKey:subElement.name];
                }
            }
        }
    }
    
    for (AlbumInfo *alb in _albumInfoArray) {
        NSLog(@"actors = %@  categories = %@ voiceActors = %@", alb.actors, alb.categories, alb.voiceActors);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
